<template>
  <view class="uni-goods-nav">
    <!-- 底部占位 -->
    <view class="uni-tab_seat"></view>
    <view class="flex uni-tab_cart-box flex">
      <view class="flex uni-tab_cart-sub-box">
        <view v-for="(item, index) in options" :key="index" class="flex uni-tab_cart-button-left uni-tab_cart-item" @click="onClick(index, item)">
          <view class="uni-tab_icon">
            <image class="image" :src="item.icon" mode="widthFix"></image>
          </view>
          <text class="uni-tab_text">{{ item.text }}</text>
          <view class="flex uni-tab_dot-box">
            <text v-if="item.info" :class="{ 'uni-tab_dots': item.info > 9 }" class="uni-tab_dot">{{ item.info > 9 ? '9+' : item.info }}</text>
          </view>
        </view>
      </view>
      <view class="uni-tab_right flex" class="flex uni-tab_cart-sub-box">
        <view v-for="(item, index) in buttonGroup" :key="index" class="flex uni-tab_button-right" @click="buttonClick(index, item)" :style="{backgroundColor: item.backgroundColor}">
          <text class="uni-tab_button-text" :style="{color: item.color}">{{ item.text }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'UniGoodsNav',
  props: {
    options: {
      type: Array,
      default: () => [
        {
          icon: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/uni-ui/goodsnav/kefu.png',
          text: '客服',
          info: 0
        },
        {
          icon: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/uni-ui/goodsnav/dianpu.png',
          text: '店铺'
        },
        {
          icon: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/uni-ui/goodsnav/carts.png',
          text: '购物车',
          info: 0
        }
      ]
    },
    buttonGroup: {
      type: Array,
      default: () => [
        {
          text: '加入购物车',
          backgroundColor: '#ff0000',
          color: '#fff'
        },
        {
          text: '立即购买',
          backgroundColor: '#ffa200',
          color: '#fff'
        }
      ]
    },
    fill: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    onClick(index, item) {
      this.$emit('click', { index, item });
    },
    buttonClick(index, item) {
      this.$emit('buttonClick', { index, item });
    }
  }
};
</script>

<style scoped>
.uni-goods-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background-color: #fff;
  border-top: 1px solid #eee;
}
.uni-tab_seat {
  height: 10px;
}
.flex {
  display: flex;
}
.uni-tab_cart-box {
  align-items: center;
}
.uni-tab_cart-sub-box {
  align-items: center;
}
.uni-tab_cart-button-left {
  align-items: center;
  padding: 10px;
}
.uni-tab_icon .image {
  width: 24px;
  height: 24px;
}
.uni-tab_text {
  font-size: 14px;
  margin-left: 5px;
}
.uni-tab_dot-box {
  margin-left: 5px;
}
.uni-tab_dots {
  display: inline-block;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  background-color: #ff0000;
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
}
.uni-tab_dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  background-color: #ff0000;
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
}
.uni-tab_right {
  flex: 1;
  justify-content: flex-end;
}
.uni-tab_button-right {
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 15px;
}
.uni-tab_button-text {
  font-size: 16px;
  font-weight: bold;
}
</style>